package com.parkinginfo.adapters;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;

import com.parkinginfo.dbhelper.Place;
import com.parkinginfo.listviews.GarageListItem;
import com.parkinginfo.listviews.PlacesListItem;
import com.parkinginfo.manager.GarageDetails;
import com.parkinginfo.manager.GarageObject;

import com.parkinginfo.manager.R;
import com.parkinginfo.manager.R.id;
import com.parkinginfo.manager.R.layout;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;



//adapter for the list. usefull to control the data that is displayed on a list
public class GarageListAdapter extends BaseAdapter{
	
	private int[] colors = new int[] { 0x30ffffff, 0x30808080 };
	private ArrayList<GarageObject> items; 
	private Context context;
	
	public GarageListAdapter(Context context,  ArrayList<GarageObject> arrayList) {
        this.context = context;
        this.items = arrayList;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		GarageListItem tli;
		System.out.println("Get View Called!");
		
		if (null == convertView) {
			tli = (GarageListItem)View.inflate(context, R.layout.garage_list_item, null);
		} else {
			tli = (GarageListItem)convertView;
		}
		int colorPos = position % colors.length;
		tli.setBackgroundColor(colors[colorPos]);
		
		GarageObject placem = items.get(position);
		System.out.println("position: "+position);
		System.out.println("location: is hard coded for now");//;;+placem.getLocation());
		tli.setPlace(placem);
		return tli;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return items.size();
	}

	@Override
	public GarageObject getItem(int position) {
		// TODO Auto-generated method stub
		return (null == items) ? null : items.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	public void forceReload() {
		notifyDataSetChanged();
	}
}
